package com.genius.smsdao.studentmanage.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.genius.smsbase.Domain.BaseEntity;
import com.genius.smsdao.majormanage.domain.Major;

import javax.persistence.*;
import java.util.List;

/**
 * @Entity:Grade 年级实体类
 * 对应数据库表名：grade
 * @author：Mie
 */
@Entity
@Table(name = "grade")
public class Grade extends BaseEntity<Long> {

    @Column
    private String name;

    //年级到学生一对多关系
    @JsonIgnoreProperties(value = "grade",allowSetters = true)
    @OneToMany(mappedBy = "grade",cascade = {CascadeType.REMOVE,CascadeType.REFRESH},fetch = FetchType.EAGER)
    private List<Student> studentList;

    //年级到专业多对一关系
    @JsonIgnoreProperties("gradeList")
    @ManyToOne(targetEntity = Major.class,cascade = {CascadeType.REFRESH},fetch = FetchType.EAGER)
    @JoinColumn(name = "major_id",referencedColumnName = "id")
    private Major major;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Student> getStudentList() {
        return studentList;
    }

    public void setStudentList(List<Student> studentList) {
        this.studentList = studentList;
    }

    public Major getMajor() {
        return major;
    }

    public void setMajor(Major major) {
        this.major = major;
    }

    @Override
    public String toString() {
        return "Grade{" +
                "name='" + name + '\'' +
                ", major=" + major +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", id=" + id +
                '}';
    }
}
